/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ModifyAthletes.java
 *
 * Created on Nov 14, 2011, 9:24:22 PM
 */
/**
 *
 * @author Sujal
 */

import javax.swing.*;

public class ModifyAthletes extends javax.swing.JDialog {
    
    private boolean saveData;
    private nanduData nandu;
   

    /** Creates new form ModifyAthletes */
    public ModifyAthletes(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        saveData=false;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        FNameT = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        LNameT = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        EmailT = new javax.swing.JTextField();
        NanduT0 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        EventL0 = new javax.swing.JComboBox();
        GenderL = new javax.swing.JComboBox();
        LevelL = new javax.swing.JComboBox();
        SchoolT = new javax.swing.JTextField();
        EventL1 = new javax.swing.JComboBox();
        NanduT1 = new javax.swing.JTextField();
        EventL2 = new javax.swing.JComboBox();
        NanduT2 = new javax.swing.JTextField();
        EventL3 = new javax.swing.JComboBox();
        NanduT3 = new javax.swing.JTextField();
        EventL4 = new javax.swing.JComboBox();
        NanduT4 = new javax.swing.JTextField();
        EventL5 = new javax.swing.JComboBox();
        NanduT5 = new javax.swing.JTextField();
        EventL6 = new javax.swing.JComboBox();
        NanduT6 = new javax.swing.JTextField();
        EventL7 = new javax.swing.JComboBox();
        NanduT7 = new javax.swing.JTextField();
        AgeGroupB = new javax.swing.JLabel();
        AgeGroupL = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        SaveB = new javax.swing.JButton();
        CancelB = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Athletes Editor");
        setAlwaysOnTop(true);
        setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
        setName("AthletesEditorForum"); // NOI18N
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Athletes Info"));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setText("First Name");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, 61, 24));

        FNameT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FNameTActionPerformed(evt);
            }
        });
        jPanel1.add(FNameT, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 20, 620, -1));

        jLabel2.setText("Last Name");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 50, 61, 24));

        LNameT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LNameTActionPerformed(evt);
            }
        });
        jPanel1.add(LNameT, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 50, 620, -1));

        jLabel3.setText("Nandu (seperated by comma, eg 312A+6A,333A )");
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 210, 340, 24));

        jLabel4.setText("Email");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 80, 61, 24));

        EmailT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EmailTActionPerformed(evt);
            }
        });
        jPanel1.add(EmailT, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 80, 640, 20));

        NanduT0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NanduT0ActionPerformed(evt);
            }
        });
        jPanel1.add(NanduT0, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 240, 470, -1));

        jLabel5.setText("University/School");
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 110, 130, 24));

        jLabel6.setText("Gender");
        jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 140, 50, 24));

        jLabel7.setText("Level");
        jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 170, 40, 24));

        jLabel8.setText("Event");
        jPanel1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 210, 40, 24));

        EventL0.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel1.add(EventL0, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 240, 210, -1));

        GenderL.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel1.add(GenderL, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 140, 140, -1));

        LevelL.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel1.add(LevelL, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 170, 220, -1));

        SchoolT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SchoolTActionPerformed(evt);
            }
        });
        jPanel1.add(SchoolT, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 110, 550, -1));

        EventL1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel1.add(EventL1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 270, 210, -1));

        NanduT1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NanduT1ActionPerformed(evt);
            }
        });
        jPanel1.add(NanduT1, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 270, 470, -1));

        EventL2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel1.add(EventL2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 300, 210, -1));

        NanduT2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NanduT2ActionPerformed(evt);
            }
        });
        jPanel1.add(NanduT2, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 300, 470, -1));

        EventL3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel1.add(EventL3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 330, 210, -1));

        NanduT3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NanduT3ActionPerformed(evt);
            }
        });
        jPanel1.add(NanduT3, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 330, 470, -1));

        EventL4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel1.add(EventL4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 360, 210, -1));

        NanduT4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NanduT4ActionPerformed(evt);
            }
        });
        jPanel1.add(NanduT4, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 360, 470, -1));

        EventL5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel1.add(EventL5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 390, 210, -1));

        NanduT5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NanduT5ActionPerformed(evt);
            }
        });
        jPanel1.add(NanduT5, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 390, 470, -1));

        EventL6.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel1.add(EventL6, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 420, 210, -1));

        NanduT6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NanduT6ActionPerformed(evt);
            }
        });
        jPanel1.add(NanduT6, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 420, 470, -1));

        EventL7.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel1.add(EventL7, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 450, 210, -1));

        NanduT7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NanduT7ActionPerformed(evt);
            }
        });
        jPanel1.add(NanduT7, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 450, 470, -1));

        AgeGroupB.setText("Age Group");
        jPanel1.add(AgeGroupB, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 140, 70, 24));

        AgeGroupL.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel1.add(AgeGroupL, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 140, 140, -1));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 720, 490));

        SaveB.setText("Save");
        SaveB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveBActionPerformed(evt);
            }
        });

        CancelB.setText("Cancel");
        CancelB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelBActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(560, Short.MAX_VALUE)
                .addComponent(SaveB)
                .addGap(18, 18, 18)
                .addComponent(CancelB)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CancelB)
                    .addComponent(SaveB))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 500, 710, 50));

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void FNameTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FNameTActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_FNameTActionPerformed

private void LNameTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LNameTActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_LNameTActionPerformed

private void EmailTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EmailTActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_EmailTActionPerformed

private void NanduT0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NanduT0ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_NanduT0ActionPerformed

private void SchoolTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SchoolTActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_SchoolTActionPerformed

private void NanduT1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NanduT1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_NanduT1ActionPerformed

private void NanduT2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NanduT2ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_NanduT2ActionPerformed

private void NanduT3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NanduT3ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_NanduT3ActionPerformed

private void NanduT4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NanduT4ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_NanduT4ActionPerformed

private void NanduT5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NanduT5ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_NanduT5ActionPerformed

private void NanduT6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NanduT6ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_NanduT6ActionPerformed

private void NanduT7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NanduT7ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_NanduT7ActionPerformed

private void SaveBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveBActionPerformed
    
    JComponent currItem=FNameT;
    try
    {
        //first name        
        currItem=FNameT;
        if(FNameT.getText().length()==0)
            throw new IllegalArgumentException("Illegal Argument");
        
        //last name        
        currItem=LNameT;
        if(LNameT.getText().length()==0)
            throw new IllegalArgumentException("Illegal Argument");
        
        //email
        currItem=EmailT;
        if(EmailT.getText().length()==0)
            throw new IllegalArgumentException("Illegal Argument");
        
        //school
        currItem=SchoolT;
        if(SchoolT.getText().length()==0)
            throw new IllegalArgumentException("Illegal Argument");
   
    } catch (IllegalArgumentException e)
    {
        JOptionPane.showMessageDialog(this, "Please Fill required fields" , "Error", JOptionPane.DEFAULT_OPTION);
        //select the item
        currItem.grabFocus();
        return;
    }
    
    try
    {
        
        for(int i=0;i<8;i++)
        {   
            JComboBox currComboBox;
            JTextField currTextField;
            switch(i)
            {
                case 0:
                    currComboBox=EventL0;
                    currTextField=NanduT0;
                    break;
                case 1:
                    currComboBox=EventL1;
                    currTextField=NanduT1;
                    break;
                case 2:
                    currComboBox=EventL2;
                    currTextField=NanduT2;
                    break;
                case 3:
                    currComboBox=EventL3;
                    currTextField=NanduT3;
                    break;
                case 4:
                    currComboBox=EventL4;
                    currTextField=NanduT4;
                    break;
                case 5:
                    currComboBox=EventL5;
                    currTextField=NanduT5;
                    break;
                case 6:
                    currComboBox=EventL6;
                    currTextField=NanduT6;
                    break;
                case 7:
                default:
                    currComboBox=EventL7;
                    currTextField=NanduT7;
                    break;                    
            }
            
            //process each data
            String eventName=(String)currComboBox.getSelectedItem();
            if(eventName.length()>0)
            {
                currItem=currTextField;
                String nanduData=currTextField.getText();
                //fix and verify nandu
                nanduData=nanduData.trim();
                while(true)
                {
                    int spaceIndex=nanduData.indexOf(' ');
                    if(spaceIndex==-1)
                        break;
                    nanduData=nanduData.substring(0,spaceIndex)+nanduData.substring(spaceIndex+1,nanduData.length());
                }
                nanduData=nanduData.replace(",,", ",");
                nanduData=nanduData.toUpperCase();
                //verify nandu
                if(verifyNandu(nanduData,eventName)==false)
                    throw new IllegalArgumentException("Invalid Nandu");
            }
        
        }
    }
    catch (IllegalArgumentException e)
    {
        //select the item
        currItem.grabFocus();
        return;
    }
    
    saveData=true;
    setVisible(false);
}//GEN-LAST:event_SaveBActionPerformed

private void CancelBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelBActionPerformed
    saveData=false;
    setVisible(false);
}//GEN-LAST:event_CancelBActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ModifyAthletes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ModifyAthletes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ModifyAthletes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ModifyAthletes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                ModifyAthletes dialog = new ModifyAthletes(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    //set Nandu Data.
    public void setNanduData(nanduData nData)
    {
        nandu=nData;        
    }
    //adds gender list
    public void addGenderList(String genderList[])
    {
        GenderL.removeAllItems();
        for(int i=0;i<genderList.length;i++)
            GenderL.addItem(genderList[i]);
    }
    
    //adds gender list
    public void addLevelList(String levelList[])
    {
        LevelL.removeAllItems();
        for(int i=0;i<levelList.length;i++)
            LevelL.addItem(levelList[i]);
    }
    
    //adds ageGroup list
    public void addAgeGroupList(String ageGroupList[])
    {
        AgeGroupL.removeAllItems();
        for(int i=0;i<ageGroupList.length;i++)
            AgeGroupL.addItem(ageGroupList[i]);
    }
    
     //adds Event list
    public void addEventList(String eventList[])
    {
        EventL0.removeAllItems();
        EventL1.removeAllItems();
        EventL2.removeAllItems();
        EventL3.removeAllItems();
        EventL4.removeAllItems();
        EventL5.removeAllItems();
        EventL6.removeAllItems();
        EventL7.removeAllItems();
        for(int i=0;i<eventList.length;i++)
        {
            EventL0.addItem(eventList[i]);
            EventL1.addItem(eventList[i]);
            EventL2.addItem(eventList[i]);
            EventL3.addItem(eventList[i]);
            EventL4.addItem(eventList[i]);
            EventL5.addItem(eventList[i]);
            EventL6.addItem(eventList[i]);
            EventL7.addItem(eventList[i]);
        }
    }
    
    //verifys nandu
    private boolean verifyNandu(String data,String event)
    {

        String tempNandu=new String(data) ;
        String value="";
        int count=0;
        while(tempNandu.length()!=0)
        {
            
            if(tempNandu.indexOf(",")==-1)
            {
                value=tempNandu;
                tempNandu="";
            }
            else
            {
               value=tempNandu.substring(0, tempNandu.indexOf(","));
               tempNandu=tempNandu.substring(tempNandu.indexOf(",")+1);
            }
            
            if(nandu.find(value,event)==null)
            {
                JOptionPane.showMessageDialog(this, "Cannot find nandu "+value+" in the event "+event+" \n" , "Error", JOptionPane.DEFAULT_OPTION);
                return false;
            }
            count++;
        }
        return true;
    }
    
    //returns the current athletes data
    public Main.AthleteFileData[] getAthleteData()
    {
        int eventsCount=0;
        for(int i=0;i<8;i++)
        {   
            JComboBox currComboBox;
            JTextField currTextField;
            switch(i)
            {
                case 0:
                    currComboBox=EventL0;
                    currTextField=NanduT0;
                    break;
                case 1:
                    currComboBox=EventL1;
                    currTextField=NanduT1;
                    break;
                case 2:
                    currComboBox=EventL2;
                    currTextField=NanduT2;
                    break;
                case 3:
                    currComboBox=EventL3;
                    currTextField=NanduT3;
                    break;
                case 4:
                    currComboBox=EventL4;
                    currTextField=NanduT4;
                    break;
                case 5:
                    currComboBox=EventL5;
                    currTextField=NanduT5;
                    break;
                case 6:
                    currComboBox=EventL6;
                    currTextField=NanduT6;
                    break;
                case 7:
                default:
                    currComboBox=EventL7;
                    currTextField=NanduT7;
                    break;                    
            }
            
            //process each data
            String eventName=(String)currComboBox.getSelectedItem();
            if(eventName.length()>0)
                eventsCount=eventsCount+1;
                
        }
        
        //allocate space
        Main.AthleteFileData aData[]=new Main.AthleteFileData[eventsCount];
        
        for(int i=0;i<eventsCount;i++)
        {
            aData[i]=new Main.AthleteFileData();
            
            aData[i].AthleteID="";
            aData[i].FirstName="";
            aData[i].LastName="";
            aData[i].Email="";
            aData[i].Gender="";
            aData[i].College="";
            aData[i].School="";
            aData[i].Experience="";
            aData[i].AgeGroup="";
            aData[i].Event="";
            aData[i].Nandu="";
            aData[i].SetupInfo="";
            aData[i].JudgeTypes="";
            aData[i].JudgeConnected="";
            aData[i].JudgeARaw="";
            aData[i].JudgeAAgree="";
            aData[i].JudgeBRaw="";
            aData[i].JudgeCRaw="";
            aData[i].JudgeCAgree="";
            aData[i].Time="";
            aData[i].Deductions="";
            aData[i].Reason="";
            aData[i].Score="0.0";

            //first name
            aData[i].FirstName=FNameT.getText();
            //last name        
            aData[i].LastName=LNameT.getText();
            //email
            aData[i].Email=EmailT.getText();
            //school
            aData[i].School=SchoolT.getText();
            //gender
            aData[i].Gender=(String)GenderL.getSelectedItem();
            //Level
            aData[i].Experience=(String)LevelL.getSelectedItem();
            //ageGroup
            aData[i].AgeGroup=(String)AgeGroupL.getSelectedItem();
            

            JComboBox currComboBox;
            JTextField currTextField;
            switch(i)
            {
                case 0:
                    currComboBox=EventL0;
                    currTextField=NanduT0;
                    break;
                case 1:
                    currComboBox=EventL1;
                    currTextField=NanduT1;
                    break;
                case 2:
                    currComboBox=EventL2;
                    currTextField=NanduT2;
                    break;
                case 3:
                    currComboBox=EventL3;
                    currTextField=NanduT3;
                    break;
                case 4:
                    currComboBox=EventL4;
                    currTextField=NanduT4;
                    break;
                case 5:
                    currComboBox=EventL5;
                    currTextField=NanduT5;
                    break;
                case 6:
                    currComboBox=EventL6;
                    currTextField=NanduT6;
                    break;
                case 7:
                default:
                    currComboBox=EventL7;
                    currTextField=NanduT7;
                    break;                    
            }

            //process each data
            String eventName=(String)currComboBox.getSelectedItem();
            if(eventName.length()>0)
            {
                String nanduData=currTextField.getText();
                //fix and verify nandu
                nanduData=nanduData.trim();
                while(true)
                {
                    int spaceIndex=nanduData.indexOf(' ');
                    if(spaceIndex==-1)
                        break;
                    nanduData=nanduData.substring(0,spaceIndex)+nanduData.substring(spaceIndex+1,nanduData.length());
                }
                nanduData=nanduData.replace(",,", ",");
                nanduData=nanduData.toUpperCase();
                //verify nandu
                if(verifyNandu(nanduData,eventName)==true)
                {
                    aData[i].Event=eventName;
                    aData[i].Nandu=nanduData;                    
                }
                
            }
            
        }
        return aData;
    }
    
    public boolean SaveClicked()
    {
        return saveData;
    }
        
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel AgeGroupB;
    private javax.swing.JComboBox AgeGroupL;
    private javax.swing.JButton CancelB;
    private javax.swing.JTextField EmailT;
    private javax.swing.JComboBox EventL0;
    private javax.swing.JComboBox EventL1;
    private javax.swing.JComboBox EventL2;
    private javax.swing.JComboBox EventL3;
    private javax.swing.JComboBox EventL4;
    private javax.swing.JComboBox EventL5;
    private javax.swing.JComboBox EventL6;
    private javax.swing.JComboBox EventL7;
    private javax.swing.JTextField FNameT;
    private javax.swing.JComboBox GenderL;
    private javax.swing.JTextField LNameT;
    private javax.swing.JComboBox LevelL;
    private javax.swing.JTextField NanduT0;
    private javax.swing.JTextField NanduT1;
    private javax.swing.JTextField NanduT2;
    private javax.swing.JTextField NanduT3;
    private javax.swing.JTextField NanduT4;
    private javax.swing.JTextField NanduT5;
    private javax.swing.JTextField NanduT6;
    private javax.swing.JTextField NanduT7;
    private javax.swing.JButton SaveB;
    private javax.swing.JTextField SchoolT;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables
}
